<template>
  <transition name="dialog" enter-class="dialogIn" leave-active-class="dialogOut">
    <div class="dialog-wrapper" v-if="isDialog">
      <div class="dialog-box">
        <h3 class="dialog-header">{{dialog.title}}</h3>
        <div class="dialog-body">
          <div>
            <p>{{dialog.contents}}</p>
            <p v-if="dialog.tipText" class="tip_text">{{dialog.tipText}}</p>
          </div>
        </div>
        <div class="dialog-footer">
          <button
            class="ake_btn ake_btn_text dialog-yes yes"
            v-if="dialog.btnGroup[0]"
            @click="confirm"
          >{{dialog.btnGroup[0]}}</button>
          <button
            class="ake_btn ake_btn_text dialog-close close"
            v-if="dialog.btnGroup[1]"
            @click="cancel"
          >{{dialog.btnGroup[1]}}</button>
        </div>
      </div>
    </div>
  </transition>
</template>

<script>
import { mapGetters, mapMutations } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      isDialog: "getIsDialog",
      dialog: "getDialog"
    })
  },
  methods: {
    ...mapMutations({
      dialogToggle: "DIALOG_TOGGLE"
    }),
    confirm() {
      if (this.dialog.confirmCallback) {
        this.dialog.confirmCallback();
      }
      this.dialogToggle(false);
    },
    cancel() {
      if (this.dialog.cancelCallback) {
        this.dialog.cancelCallback();
      }
      this.dialogToggle(false);
    }
  }
};
</script>

<style lang="less" scoped>
@import "../../assets/less/base/variables.less";
.dialogIn,
.dialogOut {
  opacity: 0;
  .dialog-box {
    transform: scale(0.4);
  }
}
.dialog-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: 15%;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 3000;
  transition: all 0.2s ease;
  .dialog-box {
    min-width: 375px;
    max-width: 420px;
    background-color: #fff;
    border-radius: 5px;
    display: flex;
    flex-direction: column;
    align-items: center;
    transition: all 0.2s ease;
    overflow: hidden;
  }
  .dialog-header {
    height: 40px;
    line-height: 40px;
    background-color: @greyF4;
  }
  .dialog-footer {
    height: 50px;
    line-height: 50px;
    // background-color: @greyF4;
  }
  .dialog-header {
    width: 100%;
    text-align: left;
    border-radius: 4px 4px 0 0;
    padding-left: @spacing * 2;
    padding-right: @spacing * 2;
    color: @black;
    font-size: 16px;
    font-weight: 500;
  }
  .dialog-body {
    width: 100%;
    min-height: 110px;
    padding: 20px 30px;
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    font-size: 14px;
    text-align: center;
    p {
      margin-bottom: 8px;
      letter-spacing: 1px;
      &.tip_text {
        font-size: 12px;
        color: #666666;
      }
    }
  }
  .dialog-footer {
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    padding-left: 40px;
    padding-right: 40px;
    .ake_btn {
      height: 32px !important;
      line-height: 32px !important;
    }
    .ake_btn + .ake_btn {
      margin-left: 18%;
    }
  }
}

@-webkit-keyframes boostIn {
  /* 默认 */
  0% {
    opacity: 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
  }
  100% {
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1);
  }
}
@keyframes boostIn {
  0% {
    opacity: 0;
    -webkit-transform: scale(0.5);
    -ms-transform: scale(0.5);
    transform: scale(0.5);
  }
  100% {
    opacity: 1;
    -webkit-transform: scale(1);
    -ms-transform: scale(1);
    transform: scale(1);
  }
}

@-webkit-keyframes boostOut {
  /* 默认 */
  0% {
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1);
  }
  100% {
    opacity: 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
  }
}
@keyframes boostOut {
  0% {
    opacity: 1;
    -webkit-transform: scale(1);
    transform: scale(1);
  }
  100% {
    opacity: 0;
    -webkit-transform: scale(0.5);
    transform: scale(0.5);
  }
}
</style>
